home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / TIMING.SWG / 0019_Wait Correction.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-26  |  6KB  |  215 lines

  1.  
  2. {$A+,B-,E-,F-,I-,N-,O-,R-,S-,V-}
  3.  
  4. (*
  5. FastWait               Copyright (c) 1991  Southern Software
  6.  
  7. Version 1.00 - 4/8/91
  8.  
  9. Allows PC's faster than 20 mhz (386/486) to properly use a delay
  10. function based upon a null looping procedure such as is used in the
  11. Turbo Pascal "Delay" procedure.  Wait is accurate for PC's as fast as
  12. 1,100 mhz equivalent!
  13.  
  14. USAGE: Simply place "FastWait" in the Uses section of your program
  15.        and replace each occurrence of "delay" in your program with
  16.        "wait".
  17.  
  18. Example-
  19. =======
  20.  
  21.      Existing program:
  22.      ----------------
  23.      Uses CRT;
  24.  
  25.      begin
  26.      writeln('This program delays for 5 seconds.);
  27.      delay(5000);
  28.      end.
  29.  
  30.      New program:
  31.      -----------
  32.      Uses FastWait, CRT;                {Now also uses "FastWait"}
  33.  
  34.      begin
  35.      writeln('This program delays for 5 seconds.);
  36.      wait(5000);                        {changed "delay" to "wait"}
  37.      end.
  38. *)
  39.  
  40. unit FastWait;
  41.  
  42.   (*   Version 1.00 - 4/8/91  *)
  43.  
  44.   {$ifdef DEBUG}
  45.     {$D+,L+}
  46.   {$else}
  47.     {$D-,L-}
  48.   {$endif}
  49.  
  50. (****************************************************************************)
  51.  interface
  52. (****************************************************************************)
  53.  
  54. var
  55.                    (* Number of loops to do for 1 ms wait.                  *)
  56.   WaitOneMS : word;
  57.  
  58.                    (* Number of loops per timer tick.                       *)
  59.   LoopsPerTick : longint;
  60.  
  61.                    (* System timer, 18.2/second.                            *)
  62.   BIOSTick : longint absolute $40:$6C;
  63.  
  64.                    (* Pauses execution for "ms" milliseconds. *)
  65. procedure Wait(ms : word);
  66.  
  67. {$ifdef VER60}
  68.  
  69.                  (* This procedure is for very short timing loops ( < 1ms)
  70.                     that cannot be handled by the delay routine.
  71.  
  72.                     The variable "LoopsPerTick" has the number of loops
  73.                     to do for one BIOS tick (18.2 of these/sec). If you
  74.                     want to delay for "X" µs, the number of loops required
  75.                     would be  "(LoopsPerTick * X) div 54945". This will not
  76.                     compile if you are using TP 4.0, 5.0 or 5.5 due to the
  77.                     conditional defines. This is because it makes use of
  78.                     the "asm" statement which is not available in TP
  79.                     versions prior to 6.0. *)
  80.  
  81.  procedure ShortDelay(NumLoops : word);
  82.   
  83. {$endif}
  84.  
  85.  
  86. (****************************************************************************)
  87.  implementation
  88. (****************************************************************************)
  89.  
  90.   {$L WAIT.OBJ}
  91.  
  92.   procedure Wait(ms : word); external;
  93.  
  94.   procedure WaitInit; external;
  95.  
  96. {$ifdef VER60}
  97.  
  98.   procedure ShortDelay(NumLoops : word); assembler;
  99.   asm
  100.     mov  cx,NumLoops
  101.     jcxz @@2
  102.     xor  di,di         (* ES:DI points to dummy address *)
  103.     mov  es,di         (* which won't change *)
  104.     mov  al,es:[di]    (* AL has the value there *)
  105.    @@1:
  106.     cmp  al,es:[di]
  107.     jne  @@2
  108.     loop @@1
  109.    @@2:
  110.   end;
  111.  
  112. {$endif}
  113.  
  114. BEGIN              (* Code to execute at start-up to calibrate the loop     *)
  115.                    (* delay.                                                *)
  116.   WaitInit
  117. END.
  118.  
  119. { XX3402 Code to WAIT.OBJ
  120. { Cut and save as WAIT.XX.  Execute : XX3402 D WAIT.XX to create WAIT.OBJ }
  121. { ------------------   CUT HERE -------------------------- }
  122.  
  123.  
  124. *XX3402-000319-080491--72--85-45848--------WAIT.OBJ--1-OF--1
  125. U+c+03R-GJEiEJBB8cUU++++J5JmMawUELBnNKpWP4Jm60-KNL7nOKxi616iA145W-++ECbg
  126. gsUK03R-GJEiEJBBhcU1+21dH7M0++-cW+A+E84IZUM+-2F-J234a+Q+8++++U2-BNM4++F1
  127. HoF3FNU5+0VR++A-+RSA4U+7Jo37J2xCFIpH++lAHoxEIp-3IZF7Eog+vt+D+++003R-GJF7
  128. HYZI8+++ld+9+++0-3R-GJE6+++WW+E+E86-YO-V++6++0Mu-LI0sjb1WxkqWpQ20x7o2nDz
  129. XgQaWUK95U++Wwjcrjx8RTX8+U0sE+0Ck9xg+9bzznDG7cc37Xc3RDgaWUIaCUJp-S9tEijq
  130. i1Q+YTTEck++WFM0+DTlck++kzWQ3E124kM-+QFF-U20l3I4+E92KUM-+E88+U++R+++
  131. ***** END OF BLOCK 1 *****
  132.  
  133. { --------------------------   CUT HERE ------------------------   }
  134. { TEST PROGRAM }
  135.  
  136. program TestWait;
  137. uses
  138.   crt,
  139.   FastWait;
  140.  
  141. var
  142.   Counter : word;
  143.   jj : longint;
  144.  
  145. BEGIN
  146.   clrscr;
  147.   HighVideo;
  148.   writeln('           Southern Software  (c) 1991'#10);
  149.   LowVideo;
  150.   writeln('This test compares the standard "delay" routine with our new "Wait"');
  151.   writeln('procedure.  Below is the calculated number of small loops the PC goes');
  152.   writeln('through for one millisecond delay.  If this number is above 1,191 then');
  153.   writeln('the "delay" routine in the Turbo CRT unit as well as those in the');
  154.   writeln('TurboPower Software Object Professional and Turbo Professional series');
  155.   writeln('will yield delays that are too short.  Our "wait" procedure is the same');
  156.   writeln('as the "delay" procedure except that it will adjust for faster machines.');
  157.   writeln;
  158.   writeln('The looping below is for 10 seconds in each case.  The seconds are shown');
  159.   writeln('and at the end, the number of BIOS ticks is shown.  A properly calibrated');
  160.   writeln('delay routine should be almost exactly 10 seconds long, which is 182 ticks.');
  161.   writeln;
  162.   writeln('To abort at any time, press any key.');
  163.   writeln(#10);
  164.   write('The delay factor for this machine is actually ');
  165.   HighVideo;
  166.   writeln(WaitOneMS);
  167.   LowVideo;
  168.   writeln(#10);
  169.   writeln('10 second delays using');
  170.   write('    CRT unit "delay" : ');
  171.   HighVideo;
  172.                    (* Delay 10 seconds using the CRT unit "delay" routine.  *)
  173.   jj := BIOSTick;
  174.   repeat
  175.   until (jj <> BIOSTick);
  176.   jj := BIOSTick;
  177.   for Counter := 1 to 10 do 
  178.     begin
  179.       delay(1000);
  180.       write(Counter)
  181.     end;
  182.   jj := (BIOSTick - jj);
  183.   LowVideo;
  184.   write('         BIOS Ticks : ');
  185.   HighVideo;
  186.   writeln(jj);
  187.   LowVideo;
  188.   write('FastWait unit "wait" : ');
  189.   HighVideo;
  190.                    (* Delay 10 seconds using FastWait unit "wait" routine.  *)
  191.   jj := BIOSTick;
  192.   repeat
  193.   until (jj <> BIOSTick);
  194.   jj := BIOSTick;
  195.   for Counter := 1 to 10 do 
  196.     begin
  197.       wait(1000);
  198.       write(Counter)
  199.     end;
  200.   jj := (BIOSTick - jj);
  201.   LowVideo;
  202.   write('         BIOS Ticks : ');
  203.   HighVideo;
  204.   writeln(jj, #10);
  205.   LowVideo;
  206.   write('Press any key to end ');
  207.   repeat
  208.   until keypressed;
  209.   while keypressed do
  210.     Counter := ord(ReadKey);
  211.   clrscr
  212. END.
  213.  
  214.  
  215.